<template>
  <div class="tenantMenu_main main_container">
    <div class="main_header">
      <div class="padding_container">
        <div class="left"><Breadcrumb /></div>
        <div class="right" />
      </div>
    </div>
    <div class="main_main">
      <div class="main_main_search">
        <div class="main_main_search_item">
          <div class="name">菜单名称</div>
          <div class="value">
            <el-input v-model="pageData.menuName" clearable @clear="getList()" @keyup.enter.native="getList()" />
          </div>
        </div>
        <div class="main_main_search_item">
          <a class="button" @click.stop="getList">
            搜索
          </a>
          <a class="button" @click.stop="refresh">
            刷新
          </a>
        </div>
      </div>
      <div ref="table_container" class="table_container">
        <el-table
          ref="table"
          :data="tableData"
          stripe
          border
          :height="tableHeight"
          style="width: 99.9%"
          :cell-class-name="cellClassName"
          row-key="menuId"
          :tree-props="{children: 'children', hasChildren: 'hasChildren'}"
        >
          <el-table-column prop="menuName" label="菜单名称" :show-overflow-tooltip="true" />
          <el-table-column prop="icon" label="图标" align="center">
            <template slot-scope="scope">
              <svg-icon :icon-class="scope.row.icon" />
            </template>
          </el-table-column>
          <el-table-column prop="orderNum" label="显示顺序" />
          <el-table-column
            prop="status"
            label="菜单状态"
          >
            <template slot-scope="scope">
              {{ scope.row.status=='1'?'正常':'停用' }}
            </template>
          </el-table-column>
          <el-table-column label="操作" align="center" fixed="right" width="180">
            <template slot-scope="scope">
              <el-button
                v-hasPermi="['system:menu:edit']"
                type="text"
                @click.stop="edit(scope.row)"
              >修改</el-button>
            </template>
          </el-table-column>
        </el-table>
      </div>
    </div>

  </div>
</template>

<script>
import { list, remove } from '@/api/system/menu'
import { handleTree } from '@/utils/jlink'
import AddOrUpdate from './addOrUpdate' // 新增或编辑页面
export default {
  name: 'Index',
  data() {
    return {
      pageData: {
        menuName: undefined,
        pageNum: 1,
        pageSize: 20,
        orderByColumn: 'updateTime',
        isAsc: 'desc'
      },
      total: 1, // 数据一共有多少条
      mainId: 'id',
      tableHeight: '0',
      tableHeight2: '0',
      tableData: [],
      tableData2: [],
      customerOptions: [],
      priceUnitOptions: [],
      contractTemplateOptions: ['国内', '国外'],
      pageName: '销售订单 - 子物料',
      triggerTag: true // 触发标志，watch是否触发
    }
  },
  computed: {
    selectedNum() {
      return this.$refs.table ? this.$refs.table.selection.length : 0
    }
  },
  mounted() {
    this.getList()
    this.$nextTick(() => {
      this.tableHeight = this.$refs.table_container.offsetHeight
    })
  },
  methods: {
    cellClassName(data) {
      if (data.column.property == 'menuName') {
        return 'menuName'
      }
    },
    getList() {
      list(this.pageData).then(res => {
        this.tableData = handleTree(res.data, 'menuId')
      })
    },
    refresh() {
      this.pageData.menuName = undefined
      this.pageData.pageNum = 1
      this.getList()
    },
    add() {
      this.$layer.iframe({// 弹框
        content: {
          content: AddOrUpdate, // 传递的组件对象
          parent: this, // 当前的vue对象
          data: {
            defaultValue: {
              parentId: 0,
              parentName: '根目录'
            }
          }// props
        },
        area: ['450px', '450px'],
        title: '新增租户菜单', // 标题
        shadeClose: false // 点击遮罩是否关闭
      })
    },
    edit(row) {
      console.log(row.menuId)
      this.$layer.iframe({// 弹框
        content: {
          content: AddOrUpdate, // 传递的组件对象
          parent: this, // 当前的vue对象
          data: {
            id: row.menuId
          }// props
        },
        area: ['450px', '450px'],
        title: '编辑菜单', // 标题
        shadeClose: false // 点击遮罩是否关闭
      })
    },
    addNext(row) {
      this.$layer.iframe({// 弹框
        content: {
          content: AddOrUpdate, // 传递的组件对象
          parent: this, // 当前的vue对象
          data: {
            defaultValue: {
              parentId: row.menuId,
              parentName: row.menuName
            }
          }// props
        },
        area: ['450px', '450px'],
        title: '新增下级租户菜单', // 标题
        shadeClose: false // 点击遮罩是否关闭
      })
    },
    deleteOne(row) {
      const _this = this
      this.$confirm('确定要删除吗', '删除确认', {
        confirmButtonText: '确定',
        cancelButtonText: '取消', cancelButtonClass: 'cancelConfirm',
        type: 'warning'
      }).then(function() {
        remove(row.menuId).then(res => {
          _this.$message({
            message: res.msg,
            type: 'success'
          })
          _this.getList()
        })
      }).catch(() => {})
    }
  }
}
</script>

<style lang="less" scoped>
.table_container{
  /deep/ .menuName{
    text-align: left;
    padding-left: 20px;
  }
}
</style>
